<?php 
class Index extends Cloud {
	
	function __construct(){
		parent::__construct();
		
		$this->load_model('model');
		$this->data['tables'] = $this->model->get_all_tables();
	}
	
	function index() {
		dbg($this->cloud->url);
	}
	
	function view(){
		
		$tb_templates = array(
			'td'=>'blocks/td',
			'tr'=>'blocks/tr',
			'tb'=>'blocks/tb',
		);
		
		/** simple **/
		$simple_num = array('apple','banana','mango');
		
		$simpl_assoc = array('a'=>'assoc apple','b'=>'assoc banana','c'=>'assoc mango');
		$simple_tpl = "<div class=\"simple\">{@_item_}</div>\r\n";
		
		$this->cloud->tpl->block('simple',$simple_tpl);
		$this->cloud->tpl->simple->simple_parse($simple_num, '_item_');;
		/** simple **/
		
		/** sql result **/
		$table 		= $this->cloud->url->query(0);
		$table 		= $this->model->get_table_content($table);

		$result_tpl = "<div class=\"sql\">#{@branch_id} {@branch_name}</div>\r\n";
		
		$block_format = array(
			'username'=>'branch_name',
			'name'=>'branch_name',
			'id'=>'branch_id',
			'Tables_in_devuser_inventory'=>'branch_name',
		);
		
		$cell_format = array(
			'name'=>'cell',
			'id'=>'cell',
		);
		
		$this->cloud->tpl->block('sql_result',$result_tpl, $block_format);
		$this->cloud->tpl->sql_result->parse($table);
		
		$this->cloud->tpl->block('table_list',$result_tpl, $block_format);
		$this->cloud->tpl->table_list->parse($this->data['tables']);
		/** sql result **/
		
		// $builder = new TB_Bldr($tb_templates, $cell_format);
		// $builder->block('branches',$string,$cell_format);		
		// echo $tb_data['branches_tb'] = $builder->build($table);
		// dbg($table);
		// dbg($table);
		// dbg($table);
		// $tb_data['branches_lt'] = $this->cloud->tpl->a->recurse()->parse($table);
		
		$data['LoL'] = "->";
		$main = "{@table_list} {@LoL} Simple {@simple} {@LoL} SQL Result {@sql_result}";
		$this->cloud->tpl->display($main,$data);
	}	

}

?>